<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$merchid=$this->checklogin();
$feelog_type=$this->feelog_type;
if($_RQ['op']=='get'){
	//$return['member2']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$member=pdo_get('jy_merch_user',array('id'=>$merchid,'uniacid'=>$_SESSION['uniacid']));
	$return['member']=$return['member2']=$member;
	$return['params']['type']=2;
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$pay_type=$pay_type?:'union';
		}
		$check=strstr($this->setting['withdrawtype'],'downline');
		if($check){
			$withdrawtype['downline']=$this->pay_types['downline'];
			$pay_type=$pay_type?:'downline';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$wxapppay_types=array();
	foreach($return['pay_types'] as $key=>$title){
		$wxapppay_types[]=array('key'=>$key,'title'=>$title);
	}
	$return['wxapppay_types']=$wxapppay_types;
	$return['feerate']=$this->setting['feerate'];
	$return['feedesc']=$this->setting['feedesc'];
	$check=strstr($this->setting['withdrawtype'],'alipay');
	if($check){
		$type_array[1]='提现到支付宝';
        $post1=$this->get('creditcash',array('pay_type'=>'alipay','mid'=>$_SESSION['uid']),array('alipay','realname','mobile'),'id desc');
	}
	$check=strstr($this->setting['withdrawtype'],'union');
	if($check){
		$type_array[2]='提现到银行卡';
        $post2=$this->get('creditcash',array('pay_type'=>'union','mid'=>$_SESSION['uid']),array('bankname','bankcard','realname','mobile'),'id desc');
        $post2['bankcard1']=$post2['bankcard'];
	}
	if($post1 || $post2) {
        $return['post'] = array_merge($post1, $post2);
    }
	$return['post']['pay_type']=$pay_type;
	//接口提现
	$apilog=model('core/member/cash')->apilog();
	if($apilog['apiplugin']){
		$return['post']['isapi']=1;
	}
	if($apilog['passed']==1){
		$return['post']['isapibank']=1;
		$return['post']['realname']=$apilog['realname'];
		$return['post']['mobile']=$apilog['mobile'];
		$return['post']['bankname']=$apilog['bankname'];
		$return['post']['bankcard']=$apilog['bankcard'];
	}
	set_html('title','商户钱包');
	exi($return);
}
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid);
	$params['type']=array(2,3,4,5);
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_merch_feelog',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['type']==2?'获得':'消费';
			if($item['type']==3 || $item['type']==2){
				$item['typetitle']='余额';
			}else{
				$item['typetitle']='积分';
			}
			
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='balance'){
	$postdata=get_postdata();
	$postdata['merchid']=$merchid;
	$this->model('creditcash')->create_balance($_SESSION['uid'],$postdata);
	exi('创建提现单成功','','/manage.credit2/');
}